<template>
	<public-view  navType="other" :navTitle="pageTitle">
		<view class="content-user-box"  @click="boxclick">
			<user-box
			v-for="(item,index) in list" 
			:key="index"
			background="#FFF"
			style="margin:10px 0;"
			:item="item"
			  />
		</view>
	</public-view>
</template>

<script>
	import userBox from "../components/user-box.vue"
	export default {
		components:{
			"user-box":userBox
		},
		data() {
			return {
				user_id:0,
				page_type:"fans",
				page:1,
				list:[]
			};
		},
		computed:{
			pageTitle(){
				return this.page_type === 'fans'?'粉丝':"关注"
			}
		},
		onLoad(o) {
			if(o.type){
				this.page_type = o.type
			}
			if (o.user_id) {
				this.user_id = o.user_id
			}

			uni.$on('fans_follow_el_act',(obj) => {
				
					let l = this.list.length
					for (let i = 0; i < l; i++) {
						if (this.list[i].show_user.id == obj.user_id) {
							
							if (obj.act == 'fans') {
								if (this.page_type == 'fans') {
									this.list.splice(i,1)
								} else {
									this.list[i].actions.remove_fans = false
								}
							} else {
								if (this.page_type == 'follow') {
									this.list.splice(i,1)
								} else {
									this.list[i].actions.remove_follow = false
								}
							}
							
							
							break
						}
					}
				
				
				// this.bgMusic= data
			    // TODO 下面执行刷新的方法
			})
		},
		onShow() {
			this.getList()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {

			getList() {
				// 粉丝关注列表
				let that = this
				let url = 'v1/user/follow_list'
				if (this.page_type  == 'fans') {
					url = 'v1/user/fans_list'
				}
				
				that.util.getRequest({
					url:url,
					data:{
						view_user_id:that.user_id,
						rows:10,
						page:that.page
					}
				}).then(res=>{
					console.log(res,"列表")
					if(that.page === 1){
						that.list = res.data.data
					}else{
						if(res.data.data.length>0){
							that.list = that.list.concat(res.data.data)
						}else{
							// that.page--
						}
					}
				})

			},
			boxclick(e) {
				console.log(e)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content-user-box{
		width: 100%;
		padding: 24upx;
		min-height: 100vh;
	}
</style>
